package com.sitech.portal.system.dao.ibatis;

import java.util.HashMap;
import java.util.List;

import com.sitech.ibnms.core.BaseIbnmsDao;
import com.sitech.ibnms.core.IPage;
import com.sitech.ibnms.core.PageForm;
import com.sitech.portal.system.dao.ISysManageUnitDao;

public class SysManageUnitDaoImpl extends BaseIbnmsDao implements ISysManageUnitDao {

	public List findFirstLevelOfManageUnitList() {
			return this.query("findFirstLevelOfManageUnitList",
					null);
	}

	public List findByParentUnitManageId(String MANAGE_UNIT_ID) {
			return this.query("findByParentUnitManageId",
					MANAGE_UNIT_ID);
	}

	public List findSelfManageId(String MANAGE_UNIT_ID) {
			return this.query("findSelfManageId", MANAGE_UNIT_ID);
	}

	public int findCountByParentUnitManage_ID(String MANAGE_UNIT_ID) {
			// return
			// this.executeBatch("findCountBySuperWORKGROUP_ID",WORKGROUP_TYPE);
			Integer size = null;
			if (MANAGE_UNIT_ID == null || MANAGE_UNIT_ID.equals("")) {
				size = (Integer) this.querySingle(
						"findCountByParentUnitManage_ID", null);
			} else {
				size = (Integer) this.querySingle(
						"findCountByParentUnitManage_ID", MANAGE_UNIT_ID);
			}
			if (size == null) {
				return 0;
			} else {
				return size.intValue();
			}

	}

	public IPage findChildManageUnitListByID(String MANAGE_UNIT_ID, PageForm pageForm) {
			String mySql = "";
			mySql = "  select MANAGE_UNIT_ID,MANAGE_UNIT_NAME,MANAGE_UNIT_DESC,PARENT_MANAGE_UNIT_ID,ENABLE "
					+ " from TB_SYS_MANAGE_UNIT  where PARENT_MANAGE_UNIT_ID='"
					+ MANAGE_UNIT_ID + "'";
			mySql += " ORDER BY MANAGE_UNIT_ID ";
			return this.findPage("findListForTB_SYS_MANAGE_UNITByPK", mySql, pageForm);
	}

	public IPage findFirstParentManageUnit(PageForm pageForm) {
			String mySql = "";
			mySql = "  select MANAGE_UNIT_ID,MANAGE_UNIT_NAME,MANAGE_UNIT_DESC,PARENT_MANAGE_UNIT_ID,ENABLE "
					+ " from TB_SYS_MANAGE_UNIT  where PARENT_MANAGE_UNIT_ID is null";
			mySql += " ORDER BY MANAGE_UNIT_ID ";
			return this.findPage(
					"findListForTB_SYS_MANAGE_UNITByPK", mySql, pageForm);
	}

	public void deleteByPKs(String pId) {

			this.delete("deleteByPKs", pId);
	}

	public HashMap findObjByPK(String unitID) {
			return (HashMap) this.querySingle(
					"findObjForTB_SYS_MANAGE_UNITByPK", unitID);
	}

	public void add(HashMap map) {
			this.insert("insertForTB_SYS_MANAGE_UNIT", map);
	}

	public void update(HashMap map) {
			this.update("updateForTB_SYS_MANAGE_UNIT", map);
	}

	public List getManageUnitTreeList() {
			return this.query("findListForManageUnit", "");
	}

	public List getManageUnitIdsTreeList(String roleID) {
			return this.query("findListForManageUnitIds", roleID);
	}

	public void deleteForROLE_MANAGERUNITIDByRoleId(String roleID) {
			this.delete("deleteForROLE_MANAGERUNITIDByRoleId", roleID);
	}

	public void insertTB_SYS_ROLE_MANAGERUNITID(HashMap map) {
			this.insert("insertFortblTB_SYS_ROLE_MANAGERUNITID", map);
	}
}
